<template>
	<view class="poster-modal" :class="[showPosterModal ? 'modal-show':'']">
		<view id='share-poster' class="share-poster">
			<view class="poster-wrap">
				<image src='/static/poster-bg.png' class="poster-bg"></image>
				<view class="poster-main">
					<image :src='goodsItem.poster' @load='loadImg' mode='aspectFill'
						:class="[goodsItem.imgLoaded ? 'imgAnt':'']" show-menu-by-longpress='true'></image>
					<view class="app-loading" v-if='!goodsItem.imgLoaded'></view>
				</view>
			</view>
			<view class="tip-text">
				<view class="line"></view>
				<view class="text">长按图片保存至相册</view>
				<view class="line"></view>
			</view>
			<view class="close" @tap='close'>
				<uni-icons type='close' size="30" color='#fff'></uni-icons>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "share-poster",
		props: {
			showPosterModal: Boolean,
			shareGoodsItem: Object
		},
		data() {
			return {
				goodsItem: this.shareGoodsItem
			};
		},
		watch: {
			shareGoodsItem: {
				immediate: true,
				handler(newV) {
					this.goodsItem = newV;
				},
			}
		},
		methods: {
			loadImg(e) {
				if (e) {
					this.$set(this.shareGoodsItem, 'imgLoaded', true)
				}
			},
			close() {
				this.$emit('close');
			}
		}
	}
</script>

<style lang="scss" scoped>
	.poster-modal {
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.4);
		position: fixed;
		left: 0;
		top: 0;
		z-index: 222;
		opacity: 0;
		visibility: hidden;
		transition: all 0.1s ease-in-out;
	}

	.modal-show {
		opacity: 1;
		visibility: visible;
	}

	.share-poster {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.poster-wrap {
		width: 538rpx;
		height: 864rpx;
		border-radius: 10rpx;
		overflow: hidden;
		position: relative;

		.poster-bg {
			width: 100%;
			height: 100%;
		}

		.poster-main {
			width: 480rpx;
			height: 790rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			overflow: hidden;
			position: absolute;
			left: 0;
			right: 0;
			top: 0;
			bottom: 0;
			margin: auto;

			image {
				width: 100%;
				height: 100%;
				opacity: 0.2;
				position: relative;
				z-index: 2;
			}
		}


		.imgAnt {
			opacity: 1 !important;
			transition-duration: 0.5s;
			transition-property: opacity;
		}
	}

	.tip-text {
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 48rpx 0 40rpx;
		color: #fff;

		.line {
			width: 100rpx;
			height: 4rpx;
			background: #fff;
		}

		.text {
			padding: 0 30rpx;
		}
	}

	.app-loading {
		display: inline-block;
		vertical-align: middle;
		width: 40rpx;
		height: 40rpx;
		background: 0 0;
		border-radius: 50%;
		border: 2rpx solid;
		animation: tui-rotate 0.7s linear infinite;
		position: absolute;
		z-index: 11;
		left: 50%;
		top: 50%;
		margin-left: -20rpx;
		margin-top: -20rpx;
		border-color: $supplier-single-color transparent $supplier-single-color transparent;
	}

	@keyframes tui-rotate {
		0% {
			transform: rotate(0);
		}

		100% {
			transform: rotate(360deg);
		}
	}
</style>